package com.msz.exception;

import com.msz.util.R;
import org.apache.ibatis.javassist.NotFoundException;
import org.apache.tools.ant.taskdefs.condition.Http;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;

/**
 * @author hx
 * @since 2021/12/2 10:05 下午
 */

@ControllerAdvice
public class HttpExceptionHandler {



    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    @ResponseBody
    public R methodNotAllowed(HttpRequestMethodNotSupportedException e) {
        return R.result(HttpStatus.METHOD_NOT_ALLOWED.value(),"接口请求方式错误");
    }

    @ExceptionHandler(JwtException.class)
    @ResponseBody
    public R jwtException(JwtException e) {
        return R.result(e.getCode(),e.getMessage());
    }

    // TODO 自定义其他异常信息




//    Spring异常	HTTP状态码
//    BindException	400
//    ConversionNotSupportedException	500
//    HttpMediaTypeNotAcceptableException	406
//    HttpMediaTypeNotSupportedException	415
//    HttpMessageNotReadableException	400
//    HttpMessageNotWritableException	500
//    HttpRequestMethodNotSupportedException	405
//    MethodArgumentNotValidException	400
//    MissingServletRequestParameterException	400
//    MissingServletRequestPartException	400
//    NoSuchRequestHandlingMethodException	404
//    TypeMismatchException	400



}
